package my.edu.common.domain;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import jakarta.validation.groups.Default;
import lombok.Data;
import my.edu.common.enumeration.OrderType;
import my.edu.common.validate.groups.Insert;
import my.edu.common.validate.groups.Purchase;
import my.edu.common.validate.groups.Sales;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Objects;

@Data
public abstract class OrderProductDetail {
    @NotNull(message = "商品id不能为空", groups = {Insert.class, Default.class})
    @Min(value = 1, message = "商品id必须大于0", groups = {Insert.class, Default.class})
    private Long productId;
    private String productNo;
    private String productName;
    private String specificationModel;//规模型号
    private String brand; // 品牌
    private String productRemark;
    private String productAttributes; // 商品属性
    private String unit; // 单位
    @NotNull(message = "数量不能为空", groups = {Insert.class, Default.class})
    @Min(value = 0, message = "数量必须大于0", groups = {Insert.class, Default.class})
    private Integer quantity; // 数量

    private String basicUnit; // 基本单位
    //@Min(value = 0, message = "数量必须大于0", groups = {Insert.class, Default.class})
    //private Integer basicQuantity; // 基本数量

//    private Integer currentStock; // 可用库存
    private Integer isGift; // 是否赠品
    private LocalDate deliveryDate; // 交货日期

    @Min(value = 0, message = "金额必须大于0", groups = {Insert.class, Default.class})
    private BigDecimal taxInclusivePrice; // 含税单价
    private BigDecimal discountRate; // 折扣率（%）
    private BigDecimal discount; // 折扣（折）
    @Min(value = 0, message = "金额必须大于0", groups = {Insert.class, Default.class})
    private BigDecimal discountAmount; // 折扣额
    @Min(value = 0, message = "金额必须大于0", groups = {Insert.class, Default.class})

    private BigDecimal amountAfterDiscount;
    private BigDecimal taxRate; // 税率（%）
    @Min(value = 0, message = "金额必须大于0", groups = {Insert.class, Default.class})
    private BigDecimal taxAmount; // 税额
    @Min(value = 0, message = "金额必须大于0", groups = {Insert.class, Default.class})
    private BigDecimal priceTaxTotal; // 价税合计

    public abstract BigDecimal getCurrentPrice() ;

    public abstract void setCurrentPrice(BigDecimal price) ;


    public abstract  OrderType getCurrentOrderType() ;


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof OrderProductDetail)) return false;  // 允许子类匹配
        OrderProductDetail that = (OrderProductDetail) o;
        return Objects.equals(productId, that.productId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(productId);
    }

    public void setPriceTaxTotal(BigDecimal priceTaxTotal) {
        this.priceTaxTotal = priceTaxTotal;
    }
}